<?php
/**
 * Created by PhpStorm.
 * User: Orange
 * Date: 2018/5/8
 * Time: 13:59
 */

namespace app\index\logic;


use think\Db;
use think\Exception;

class CategoryLogic
{
    /**
     * 根据父ID获取分类信息
     * @return array
     */
    public function GetAllCategory($parent_id)
    {
        Db::startTrans();
        try {
            $list = model('Category')->where(array('parent_id'=>$parent_id))->where(array('is_delete'=>0))->select();
            Db::commit();
            return array('status' => 1, 'data' => $list);
        } catch (Exception $e) {
            Db::rollback();
//            return array('status' => 0, 'error' => $e->getMessage());
            return array('status' => 0, 'error' => "数据出错");
        }
    }
    public function GetKingdomCategory()
    {
        Db::startTrans();
        try {
            $list = model('Category')->where(array('current_level'=>0))->where(array('is_delete'=>0))->select();
            Db::commit();
            return array('status' => 1, 'data' => $list);
        } catch (Exception $e) {
            Db::rollback();
//            return array('status' => 0, 'error' => $e->getMessage());
            return array('status' => 0, 'error' => "数据出错");
        }
    }
}